package com.aaa.controller;

import com.aaa.entity.Result;
import com.aaa.utils.MyConstants;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/8/29 15:31
 * @description：所有的controller的基础类
 * @modified By：
 * @version: 1.0
 */
@ControllerAdvice
public class BaseController {


    /**
     * @create by: 张恒
     * @description: 错误页面
     * @create time: 2022/9/7 22:20
     * @param
     * @return
     */
    /*@ExceptionHandler(Exception.class)
    public ModelAndView toErrorPage(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("500");
        return modelAndView;
    }*/

    /**
     * @param
     * @return com.aaa.entity.Result
     * @create by: ludi（206913808@qq.com）
     * @description: 返回成功，不携带数据，适用于增删改
     * @create time: 2022/8/29 15:31
     */
    public Result success() {

        Result result = new Result(MyConstants.SUCCESS_CODE, MyConstants.SUCCESS_MSG, null, null);
        return result;
    }

    /**
     * @param
     * @return com.aaa.entity.Result
     * @create by: ludi（206913808@qq.com）
     * @description: 返回成功，不携带数据，适用于增删改
     * @create time: 2022/8/29 15:31
     */
    public Result fail() {
        Result result = new Result(MyConstants.FAIL_CODE, MyConstants.FAIL_MSG, null, null);
        return result;
    }

    /**
     * @param msg
     * @return com.aaa.entity.Result
     * @create by: ludi（206913808@qq.com）
     * @description: 携带特殊错误信息
     * @create time: 2022/8/29 15:32
     */
    public Result fail(String msg) {
        Result result = new Result(MyConstants.FAIL_CODE, msg, null, null);
        return result;
    }

    /**
     * @param data
     * @return com.aaa.entity.Result
     * @create by: ludi（206913808@qq.com）
     * @description: 操作成功，需要返回数据，例如  添加的时候返回主键
     * @create time: 2022/8/29 15:32
     */
    public Result success(Object data) {
        Result result = new Result(MyConstants.SUCCESS_CODE, MyConstants.SUCCESS_MSG, null, data);
        return result;
    }

    /**
     * @param data
     * @param count
     * @return com.aaa.entity.Result
     * @create by: ludi（206913808@qq.com）
     * @description: 分页查询
     * @create time: 2022/8/29 15:33
     */
    public Result success(Object data, Long count) {
        Result result = new Result(MyConstants.SUCCESS_CODE, MyConstants.SUCCESS_MSG, count, data);
        return result;
    }

    /**
     * @param msg
     * @return com.aaa.entity.Result
     * @create by: ludi（206913808@qq.com）
     * @description: 需要特殊提示信息的
     * @create time: 2022/8/29 15:33
     */
    public Result success(String msg) {
        Result result = new Result(MyConstants.SUCCESS_CODE, msg, null, null);
        return result;
    }
}
